package com.genesis.web.controller;


import com.genesis.mall.common.Result;
import com.genesis.mall.dto.PageDto;
import com.genesis.mall.dto.ProductDetailVO;
import com.genesis.mall.entity.PmsProduct;
import com.genesis.mall.entity.PmsProductCategory;
import com.genesis.mall.service.IPmsProductCategoryService;
import com.genesis.mall.service.IPmsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/product")
public class PmsProductController {

    @Autowired
    private IPmsProductCategoryService categoryService;

    @Autowired
    private IPmsProductService pmsProductService;

    /**
     * 以树形结构获取所有商品分类
     * @return
     */
    @GetMapping("/categoryTreeList")
    public Result<List<PmsProductCategory>> treeList(){
            return Result.success(categoryService.getAll());
    }

    /**
     * 获取前台商品详情
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public Result<ProductDetailVO> productDetail(@PathVariable Long id){
        return Result.success(pmsProductService.getProductDetail(id));
    }

    /**
     * 综合搜索 筛选 排序
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @param sort
     * @return
     */
    @GetMapping("/search")
    public Result<PageDto<PmsProduct>> search(String keyword, Integer pageNum, Integer pageSize, Integer sort,Long brandId,
                                              Long productCategoryId){
            return Result.success(pmsProductService.search(keyword,pageNum,pageSize,sort,brandId,productCategoryId));
    }

}
